﻿Option Explicit On

Namespace Blog

    <CLSCompliant(True)> _
    Public Class Blog

        Inherits BlogSpark.Common.ObjectBase

#Region "Members"

        Private _BlogId As Integer
        Private _title As String
        Private _description As String
        Private _Url As String
        Private _rssUrl As String
        Private _Created As DateTime
        Private _Modified As DateTime
        Private _isAllowAnonymous As Boolean
        Private _isAllowHTMLComments As Boolean
        Private _isRequireCaptcha As Boolean

#End Region

#Region "Constructors"

        Public Sub New()
        End Sub

#End Region

#Region "Methods"

        Public Overrides Sub Fill(ByVal dr As System.Data.DataRow)

            _BlogId = dr(enumBlogFields.BlogId)
            Title = dr(enumBlogFields.Title)
            Description = dr(enumBlogFields.Description)
            URL = dr(enumBlogFields.Url)
            RssURL = dr(enumBlogFields.RssUrl)
            Created = dr(enumBlogFields.Created)
            Modified = dr(enumBlogFields.Modified)
            AllowAnonymous = dr(enumBlogFields.IsAllowAnonymous)
            AllowHTMLComments = dr(enumBlogFields.IsAllowHTMLComments)
            RequireCaptcha = dr(enumBlogFields.IsRequireCaptcha)

        End Sub

        Public Sub Save()

            If _BlogId = 0 Then
                _BlogId = BlogSpark.DataProvider.SPs.InsertBlog(BlogSpark.DataProvider.Data.ConnectionType, Title, URL, Created, Modified)
            Else
                BlogSpark.DataProvider.SPs.UpdateBlog(BlogSpark.DataProvider.Data.ConnectionType, BlogID, Title, URL, Created, Modified)
            End If

        End Sub

        Public Sub Delete()

            BlogSpark.DataProvider.SPs.DeleteBlog(BlogSpark.DataProvider.Data.ConnectionType, BlogID)

        End Sub

#End Region

#Region "Properties"

        Public ReadOnly Property BlogID() As Integer
            Get
                Return _BlogId
            End Get
        End Property

        Public Property Title() As String
            Get
                Return _title
            End Get
            Set(ByVal value As String)
                _title = value
            End Set
        End Property

        Public Property Description() As String
            Get
                Return _description
            End Get
            Set(ByVal value As String)
                _description = value
            End Set
        End Property

        Public Property URL() As String
            Get
                Return _Url
            End Get
            Set(ByVal value As String)
                _Url = value
            End Set
        End Property

        Public Property RssURL() As String
            Get
                Return _rssUrl
            End Get
            Set(ByVal value As String)
                _rssUrl = value
            End Set
        End Property

        Public Property Created() As DateTime
            Get
                Return _Created
            End Get
            Set(ByVal value As DateTime)
                _Created = value
            End Set
        End Property

        Public Property Modified() As DateTime
            Get
                Return _Modified
            End Get
            Set(ByVal value As DateTime)
                _Modified = value
            End Set
        End Property

        Public Property AllowAnonymous() As Boolean
            Get
                Return _isAllowAnonymous
            End Get
            Set(ByVal value As Boolean)
                _isAllowAnonymous = value
            End Set
        End Property

        Public Property AllowHTMLComments() As Boolean
            Get
                Return _isAllowHTMLComments
            End Get
            Set(ByVal value As Boolean)
                _isAllowHTMLComments = value
            End Set
        End Property

        Public Property RequireCaptcha() As Boolean
            Get
                Return _isRequireCaptcha
            End Get
            Set(ByVal value As Boolean)
                _isRequireCaptcha = value
            End Set
        End Property

#End Region

#Region "Enum"

        Private Enum enumBlogFields As Byte

            BlogId = 0
            Title
            Description
            Url
            RssUrl
            Created
            Modified
            IsAllowAnonymous
            IsAllowHTMLComments
            IsRequireCaptcha

        End Enum

#End Region

    End Class

End Namespace

